#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/wait.h>
#include<sys/types.h>
#include<assert.h>



int main(int argc,char*argv[])
{

    printf("process is running...\n");
    pid_t id = fork();
    assert(id!=-1);
    if(id == 0)
    {
        // 类比命令行怎么写
        sleep(1);
        
        execvp(argv[1],&argv[1]);
        
        
        //execl("./mybin","mybin",NULL);
        //execlp("ls","-a","-l","--color=auto",NULL);
        //char* const argv[]= {"ls","-a","-l",NULL};
        //execv("/usr/bin/ls",argv);
        //execvp("ls",argv);
        //execl("/usr/bin/ls","ls","-a","-l","--color=auto",NULL);
        //char*const envp[]={(char*)"MYENV=1111222233334444",NULL};
        //extern char** environ;
        //putenv((char*)"MYENV=11112222333344445555");
        //setenv("MYENV","11112222333344445555",1);
        //execle("./mybin","mybin",NULL,environ);
        exit(1);
    }

    int status = 0;
    pid_t ret = waitpid(id,&status,0);
    if(ret>0)
    {
        printf("等待成功! ret: %d exit code: %d sign: %d\n",ret,(status>>8)&0xFF,(status&0x7F));
    }










    //printf("process running done...\n");



    //.c -> exe -> load -> process -> 运行 ->执行我们现在所写的代码
    //printf("process is running...\n");
    
    //execl("/usr/bin/ls","ls",NULL);
    
    //printf("process running done...\n");
    return 0;
}





